package com.iking.housekeeping.util.archives;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Aop拦截Controller记录日志
 * 
 * @author klaus
 *
 */
@Aspect
@Component
public class HttpAspect {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Pointcut("execution(public * com.iking.housekeeping.*.controller.*.*(..))")
	public void log() {
		
	}

	@Before("log()")
	public void doBefore(JoinPoint joinPoint) {
//		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//		HttpServletRequest request = attributes.getRequest();
		// 类名
		logger.info(joinPoint.getSignature().getDeclaringTypeName());
		//方法名
		logger.info(joinPoint.getSignature().getName());
		// 参数
		logger.info("args={}", joinPoint.getArgs());
	}

	@After("log()")
	public void doAfter() {
		logger.info("test");
	}

	@AfterReturning(returning = "object", pointcut = "log()")
	public void doAfterReturning(Object object) {
		logger.info("response={}", object.toString());
	}

}
